package cn.ffcs.uec.post.vo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import lombok.Getter;
import lombok.Setter;
import cn.ffcs.uec.organization.vo.OrganizationRelationVo;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.zkplus.zul.tree.node.TreeNodeEntity;

public class BasePostVo implements Serializable, TreeNodeEntity {
	private static final long serialVersionUID = 2972730116574041173L;

	@Getter
	@Setter
	private Long postId;

	@Getter
	@Setter
	private String code;

	@Getter
	@Setter
	private String pcode;

	@Getter
	@Setter
	private String postname;
	
	@Getter
	@Setter
	private String lv;

	// ///////////////////////
	/**
	 * 根节点
	 */
	@Getter
	@Setter
	private String rootId = "00000000";

	/**
	 * 是否是根节点
	 */
	@Setter
	private Boolean isRoot = false;

	public Boolean getIsRoot() {
		return this.isRoot;
	}

	public BasePostVo() {
		super();
	}

	public static BasePostVo newInstance() {
		return new BasePostVo();
	}

	@Override
	public boolean isGetRoot() {
		return this.isRoot;
	}

	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<TreeNodeEntity> getRoot() {
		if (!StrUtil.isNullOrEmpty(this.rootId)) {
			String sqlStr = " SELECT * FROM BASE_POST WHERE CODE = ? ";
			List<Object> params = new ArrayList<Object>();
			params.add(this.rootId);

			List<BasePostVo> list = OrganizationRelationVo.repository()
					.jdbcFindList(sqlStr, params, BasePostVo.class);
			
			Object object = list;
			return (ArrayList<TreeNodeEntity>)object;
		}

		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<TreeNodeEntity> getChildren() {
		if (!StrUtil.isNullOrEmpty(this.code)) {
			String sqlStr = " SELECT * FROM BASE_POST WHERE PCODE = ? ";
			List<Object> params = new ArrayList<Object>();
			params.add(this.code);

			List<BasePostVo> list = OrganizationRelationVo.repository()
					.jdbcFindList(sqlStr, params, BasePostVo.class);
			
			Object object = list;
			return (ArrayList<TreeNodeEntity>)object;
		}

		return null;
	}

	@Override
	public String getLabel() {
		if (!StrUtil.isNullOrEmpty(this.postname)) {
			return this.postname;
		} else {
			return "";
		}
	}

}
